package com.guigu.youxuan.controller;

import com.guigu.youxuan.service.IBackRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@RestController
@RequestMapping("/backRoleMenu")
public class BackRoleMenuController {

    @Autowired
    private IBackRoleMenuService backRoleMenuService;

    /**
     * 当前角色的菜单id
     * @param roleId
     * @return
     */
    @RequestMapping("/queryMenuIdByRoleId/{roleId}")
    public long [] queryMenuIdByRoleId(@PathVariable Long roleId) {
        long[] menuId= backRoleMenuService.queryMenuIdByRoleId(roleId);
        return menuId;
    }

    /**
     * 角色分配菜单
     * @param menuIdList
     * @param roleId
     * @return
     */
    @RequestMapping("/updateRoleMenuByRid/{roleId}")
    public String updateRoleMenuByRid(@RequestBody List<Long> menuIdList,
                                      @PathVariable Long roleId) {
        backRoleMenuService.updateRoleMenuByRid(menuIdList,roleId);
        return "该角色分配菜单成功！";
    }
}
